package com.bw.zg3_day05zy.news

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bw.base.entity.NewsBeanItem
import com.bw.base.net.ApiService

class NewsDataSource(val apiService: ApiService): PagingSource<Int, NewsBeanItem>() {
    override fun getRefreshKey(state: PagingState<Int, NewsBeanItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, NewsBeanItem> {
        try {
            val news = apiService.getNews()
            return LoadResult.Page(news.data,null,null)
        }catch (e: Exception){
            return LoadResult.Error(e)
        }
    }
}